/*TCSS 360 ConferenceGuru
 * 
 * Author: Aaron Kaufman
 * 
 * Edited by: Lawrence Grass - 11/27 to set the deadline
 * 
 * This class holds all of users in the conference, and stands at the highest level of the composition hierarchy besides the Portal class.
 * It controls adding new papers to the conference, and adding new roles to the conference.
 * 
 */
package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class Conference implements Serializable {

	
	private static final long serialVersionUID = 754131147781294019L;
	private String my_conference_title;
    private final String my_program_chair_name;
    private final ProgramChair my_program_chair;
    private final Map<String, Author> my_user_to_author;
    private String my_conference_deadline = "None";
    
    public Conference(String conf_name, ProgramChair the_prog, String the_user)
    {
    	my_conference_title = conf_name;
        my_program_chair = the_prog;
        my_program_chair_name = the_user;
        my_user_to_author = new HashMap<String, Author>();
    }
    
    public Conference(String conf_name, String the_user)
    {
        my_conference_title = conf_name;
        my_program_chair = new ProgramChair(new ArrayList<ConferencePaper>(),
                new HashMap<String, SubProgramChair>(),
                new HashMap<String, Reviewer>(),
                the_user);
        my_program_chair_name = the_user;
        my_user_to_author = new HashMap<String, Author>();
    }
    
    public void setDeadline(String the_conference_deadline)
    {
        my_conference_deadline= the_conference_deadline;
    }
    
    public String getDeadline()
    {
        return my_conference_deadline;
    }
    public String getConfTitle()
    {
    	return my_conference_title;
    }
    
    public Collection<ConferencePaper> getConferencePapers()
    {
        return my_program_chair.getPapers();
    }
   

    
    public Author getAuthorRole(String the_user)
    {
        if (my_user_to_author.containsKey(the_user))
        {
            return my_user_to_author.get(the_user);
        }
        return null;
    }
    

    public ProgramChair getProgramChair()
    {
        return my_program_chair;
    }
    
    public String getProgChairUserName()
    {
        return my_program_chair_name;
    }

    

    
    public void addPaperToReviewer(Reviewer the_reviewer, ConferencePaper the_paper)
    {
        the_reviewer.setManuscript(the_paper);
    }
    
    /*
     * Preconditions:  The author should not be currently in the conference.
     * Postconditions:  The author is placed in the conference under the given username.
     * 
     */
    public void addAuthor(String the_user, String the_author)
    {
        Author new_role = new Author(new ArrayList<ConferencePaper>(), the_author);
        my_user_to_author.put(the_user, new_role);
    }
    
    /*
     * Adds a paper to the conference, and creates a new author role to handle it, UNLESS 
     * that person is already an author, in which case that author role is simply assigned the paper.
     */
    public void addPaperToConference(String the_author, String the_title, String the_manuscript_file, String the_user,
    		                         String the_email, String the_category_of_paper, String the_keywords, 
    		                         String the_abstract)
    {

        ConferencePaper paper = new ConferencePaper(the_title, the_manuscript_file, the_author);
        paper.setEmail(the_email);
        paper.setCategoryOfPaper(the_category_of_paper);
        paper.setKeywords(the_keywords);
        paper.setAbstractOfPaper(the_abstract);
        
        if (!my_user_to_author.containsKey(the_user))
        {
            my_user_to_author.put(the_user, new Author(new ArrayList<ConferencePaper>(), the_user));
        }
        

        Author author_role = my_user_to_author.get(the_user);
        author_role.addPaper(new ConferencePaper(the_title, the_manuscript_file, the_author));
        my_program_chair.getPapers().add(paper);

    }
    /*
     * Creates a new reviewer in the conference, which can be accessed by the_user
     */
    public void designateReviewer(String the_user)
    {
        my_program_chair.designateReviewer(the_user);
    }
    
    public String toString()
    {
        return my_conference_title;
    }
    
    
}
